home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Environments / MacMETH 3.2.4 / MEdit ƒ / Macros ƒ / Macros.MCR < prev   
Text File  |  1996-06-20  |  31KB  |  996 lines

  1. **********************************************************************************
  2. * This macro file is useful for Modula-2 programming. It allows you to
  3. * insert all important program-structures with one key.
  4. * derived from Pascal.Mcr of   Matthias Aebi  31.03.86
  5. * written           : 16.10.86   Alex Itten
  6. * Last modification : 20.10.86   Alex Itten
  7. *                      18.08.87   Andreas Fischlin
  8. *                      31.08.87   Andreas Fischlin to MEdit V1.54 adapted
  9. *                      11.02.88   A. Fischlin, Wrap and rearrange comment
  10. *                                 macro (22,36) added
  11. *                      11.09.88   Olivier Roth, adapted to pers. use
  12. *                      24.10.88   Olivier Roth, some bug fixes
  13. *                      30.01.89   Andreas Fischlin, adapted to pers. use
  14. *                                 and update to 1989 version made
  15. *                      13.02.89   Andreas Fischlin some minor changes in
  16. *                                 macro procedure (without VAR), and
  17. *                                 small format fixes in macro 5, 35, 44
  18. *                                 MacPlus version separated from Mac IIx
  19. *                                 version and making a generic version
  20. *                                 (see list of markers below)
  21. *                      14.02.89   Correction for Mac Plus
  22. *                      27.02.89   Thomas Nemecek, adapted to pers. use
  23. *                      10.06.89   Olivier Roth, menu layout & some short
  24. *                                 cuts (cmd-W is Close, Wrap->A).
  25. *                      23.08.89   A. Fischlin adapted to new versions of
  26. *                                 MacMETH, DM, and ModelWorks
  27. *                                 Case now Option^S instead of Option^A
  28. *                                 so that wrap in both versions may use
  29. *                                 Command^A resp. Option^A
  30. *                      25.10.89   O.R. removal of CONST, TYPE, VAR.
  31. *                                 Goto M2-Error added.
  32. *                      25.10.89   A.F. all versions corrected, new import
  33. *                                 list for ModelWorks 1.3 inserted
  34. *                      30.04.90   A.F. all versions corrected for DM 2.0,
  35. *                                 MacMETH 2.6+ and ModelWorks 2.0
  36. *                      15.09.90   A.F. versions corrected for DM 2.01 and
  37. *                                 ModelWorks 2.01
  38. *                      20.09.90   O.R.: version for MacMETH error support,
  39. *                                 complete revision.
  40. *                      01.10.90   O.R.: version 1.6 (with new MComp version)
  41. *                      26.10.90   O.R.: version 1.62 (with new MComp & MEdit)
  42. *                      09.11.90   O.R.: version 1.64 (with new MComp & MEdit)
  43. *                      24.11.90   O.R.: version 1.65 for students & ETH faculty
  44. *                      11.01.91   O.R.: version 1.66 for students & ETH faculty
  45. *                     12.06.91   A.F.: version 1.70 using no longer absolute
  46. *                                path to MacMETH but now relative path to
  47. *                                RAMSES shell
  48. *                      24.06.91     A.F.: Bug fix in macro «Find M2-Error» where
  49. *                                 WName result was returned inconsistently. Now
  50. *                                 using $1 as intermediate storage variable.
  51. *                      01.07.91   O.R.: version 1.71 for students & ETH faculty
  52. *                      12.07.91   O.R.: version 1.72 for students & ETH faculty
  53. *                      13.08.91   O.R.: version 1.73 for students & ETH faculty
  54. *                      20.11.91   A.F.: Minor version corrections and updates
  55. *                                 for RAMSES shell 1.02b4, MacMETH 3.0, DM 2.031,
  56. *                                 and ModelWorks 2.031.
  57. *                      13.01.92   D.G.: Updates for RAMSES Shell 1.2, 
  58. *                                 MacMETH 3.0, DM 2.2 and ModelWorks 2.2.
  59. *                      10/03/92   D.G.: Updates for RAMSES Shell 1.2b0, MacMETH 3.2 
  60. *                      31/08/92     A.F.: Version 1.79 
  61. *                     29/09/92   jth final release for MacMETH 3.2.
  62. *                      02/10/92     - J. Thoeny as user of this generic version added
  63. *                                Reconstruction of a generic version from
  64. *                                - J. Thoeny's new XX version
  65. *                                - Avoiding any non ASCII characters to allow
  66. *                                for easier port of code to MS-DOS PC and Unix 
  67. *                                machines
  68. *                      22/10/92     A.F.: Support for MiniRAMSESShell added, i.e.
  69. *                                mini* markers added
  70. *                     24/10/92   Launch shell sends now a comp message ('DMEv',231,0,0)
  71. *                      08/11/92     For RAMSES Mini shell support Cmd^0 must not
  72. *                                 send a 'MnCh' high level event.
  73. *                      13/11/92     Support for new MEdit version 1.8
  74. *                     02/12/92   Added Launch Shell and Simulate Macro
  75. *                      05/12/92     A.F.: Adapted for RAMSES 2.0
  76. *                     29/04/93   jth support for warning 263
  77. *                      07/06/93     A.F.: Adapted for RAMSES 2.2
  78. *                     29/04/93   jth MacMETH 3.2.2
  79. *                     12/09/95   af MacMETH 3.2.3
  80. *                      14/05/96   af removal of versions in names for more generic
  81. *                                macros
  82. *
  83. **********************************************************************************
  84. * Versions:
  85. *    M2-Generic(1.80).MCR
  86. *    MComp 1.40
  87. *    MEdit 1.80
  88. **********************************************************************************
  89. * Legend:
  90. *  Δ            - Shift
  91. *  xNum         - key x on numeric key pad
  92. *  Opt          - Option (alt) key
  93. *  ^            - between two keys means press simultaneously
  94. *  CursLeft     - Cursor Left
  95. *  CursRight    - Cursor Right
  96. *  CursUp       - Cursor Up
  97. *  CursDown     - Cursor Down
  98. *
  99. *  Version markers: This file is a generic macro version.  The beginning 
  100. *                    of the lines are marked with a particular comment string
  101. *                    see list below.  To produce a particular version of these
  102. *                    macros simply remove all markers of the particular kind
  103. *                    to make the particular lines active.  Otherwise the macro
  104. *                    compiler will treat them as a comment only.  Warning: Be
  105. *                    careful not to destroy this generic version while making
  106. *                    a particular version (Use menu command Save as... and NOT
  107. *                    Save!).
  108. *  List of used markers (first '*' is omitted to allow for global remove, so
  109. *                         that the list below is not destroyed while producing
  110. *                         a particular version)
  111. *    af*        - Line used in A. Fischlin's version for any Mac
  112. *    jt*        - Line used in J. Thoeny's version for any Mac
  113. *    or*        - Line used in O. Roth's version for any Mac SE & II sg
  114. *    tn*        - Line used in T. Nemecek's version for any Mac II sg
  115. *    XX*        - Line used in version for: student, staff & faculty of ETHZ
  116. *    mini*      - Line used in version for Mini RAMSES Shell
  117. *  legend: sg = swiss german keyboard, us = us ascii keyboard
  118. **********************************************************************************
  119.  
  120. *
  121. * Globally used string resources ('STR '):
  122. * ID 0-4
  123. *
  124. * Globally used string variables:
  125. *
  126. * $9 : path to folder containing "ErrList.DOK" (relative to MacMETH folder)
  127. * $8 : name of the M2-shell
  128. * $7 : last name of user
  129. * $6 : first name of user
  130. * $5 : pattern expression for finding M2-error mark
  131. * $4 : 
  132. * Locally used:
  133. * $3 : div.
  134. * $2 : procedure name
  135. * $1 : div.
  136. * $0 : module name
  137.  
  138. *
  139. * Locally used numeric variables:
  140. * #0, #1, #2, #6-#9
  141. * --------------------------------------------------------------------------------
  142.  
  143.  
  144.  
  145. * 01
  146. * Find all compiled M2 files and open the erroneous/first in list
  147. * NOTE: this is the autoexec macro!
  148. !"Open work file[s]/0" • {
  149. *   at least one window must be open for autoexec macro
  150. *    New;  IF Window(1)  { Window(0);  Close };
  151.     Set( $7, GetStr(0) );
  152.     IF Len($7) = 0 {
  153. * adapt here for your configuration:
  154. * *********************************
  155. *jt*        Set($8," MacMETH");        Set($9,":M2Tools:");      Set($7,"Thoeny");                 Set($6,"Juerg");
  156. *or*        Set($8," MacMETH");        Set($9,":M2Tools:");      Set($7,"Roth");                   Set($6,"Olivier");
  157. *af*        Set($8," RMSMacMETH");    Set($9,":M2Tools:");      Set($7,"Fischlin");               Set($6,"Andreas");
  158. *tn*        Set($8," MacMETH");        Set($9,":M2Tools:");      Set($7,"Nemecek");                Set($6,"Thomas");
  159.         Set($8," MacMETH");        Set($9,":M2Tools:");      Set($7,"(*.Your last name.*)"); Set($6,"(*.Your first name.*)");
  160. * *********************************
  161.         Call(09);  }
  162.     ELSE  {
  163.         Set( $6, GetStr(1) );
  164.         Set( $8, GetStr(2) );
  165.         Set( $9, GetStr(3) );
  166.     };
  167.     Set($5,"†[ 0-9][ 0-9][0-9]†");
  168.     IF NOT Open( "err.DAT")  {
  169.       Alert( Concat( "Can't find and open the Modula-2 compilation error file: '", "err.DAT", "'" ) );
  170.       Alert( "Move MEdit and/or compile your Modula-2 source file(s)" );  }
  171.     ELSE  {
  172.       Set(#0,0);
  173.       Select(0,0);
  174.       Set(#1,AbsPos);
  175.       WHILE Find("¿")  {
  176.         Set(#2, AbsPos-#1 );  Set(#2, #2 MOD 7 );
  177.         IF #2 = 0  {
  178. *          i.e. filename mark found
  179. *         NOTE: ".*[]" contains 0C in brackets!
  180.           EFind(".*[]");
  181.           Select(L.,C.|L.,C:-1);
  182.           Set($1,$S);
  183.           Select(L.,C:+1|L.,C:+2);
  184.           Set(#1,AbsPos);        
  185.           IF StrCmp($S,"¡",1) = 0  {
  186.             IF NOT Open($1)  {
  187.               Alert( Concat("Can't find and open source file '", $1, "' containing Modula-2 errors!") );
  188.               Alert( "Try Macro 'Configure' and/or compile your Modula-2 source file(s)" );
  189.               SelAbs(AbsPos+1);  }
  190.             ELSE  {
  191.               Set(#0,#0+1);
  192.               Window(#0);
  193.             };
  194.           };
  195.           SelAbs(AbsPos-1);
  196.         };
  197.       };
  198.       IF #0 = 0 {
  199. *       no file with compilation errors, open first:
  200.         Select(0,1);
  201.         EFind(".*[]");
  202.         Select(L.,C.|L.,C:-1);
  203.         Set($1,$S);
  204.         IF NOT Open($1)  {
  205.           Alert( Concat("Can't find and open Modula-2 file '", $1, "'") );
  206.           Alert( "Try Macro 'Configure' and/or compile your Modula-2 source file(s)" );  }
  207.         ELSE  {
  208.           Set(#0,#0+1);
  209.           Window(#0);
  210.         };
  211.       };
  212.       Close;
  213.       IF #0 > 0  Call(02);
  214.     };
  215. };
  216.  
  217. * 02
  218. * jumps ,to the next Modula-2 error mark and displays an alert
  219. "Find next error/E" {
  220.     IF Len($S) > 5 Select(L.,C:-5|L.,C:);
  221.     IF EFind ($5) {
  222.       Select(L.,C.|L.,C:)!;
  223.       Set($3,SubStr($S,2,3));
  224.       Set(#8,Val($3));
  225.       IF #8 = 263 {
  226.           Select(L.,C<|L.,C:);
  227.           Select(L.,C.-1|L.,C:);
  228.           Select(L.,C<|L.,C:);
  229.           Select(L.,C>|L.,C:);
  230.           Select(L.,C.-1|L.,C:);
  231.         Set(#7,Ord(SubStr($S,1,1)));
  232.         IF #7 = Ord("=")  {
  233.               Select(L.,C.-1|L.,C:);
  234.             Select(L.,C<|L.,C:);
  235.         } ELSE {
  236.             IF NOT #7 = Ord(",") AND NOT #7 = Ord(" ") {
  237.                 Select(L.,C.+1|L.,C:);
  238.             };
  239.         };
  240.           IF Len($S) < 5{
  241.               Select(L.,C:-5|L.,C:);
  242.               Select(L.,C<|L.,C:);
  243.           };
  244.           Beep;
  245.       };
  246.       Set(#7,0);  Set(#8,0);  Set(#9,0);
  247.       WHILE #8 = 0 AND #7 = 0  {
  248.         IF Window(#9)  {
  249.           IF StrCmp(WName,"ErrList.DOK",0) = 0  Set(#8,1);
  250.         }
  251.         ELSE
  252.           Set(#7,1);
  253.         Set(#9,#9+1);
  254.       };
  255.       IF #8 = 0  {
  256.         IF Open( Concat($9,"ErrList.DOK") )  {
  257.           PlaceW( ScrH-50, 2, ScrH-2, 500 );
  258.           Set(#8,1);
  259.         }
  260.         ELSE
  261.           Alert( Concat("Can't find and open compilation error message file '",$9,"ErrList.DOK'"));
  262.       };
  263.       IF #8 = 1  {
  264.         Select(VAL($3)-40,0);
  265.         Set( $1, Concat( "^- ", $3, " .*" ) );
  266.         EFind( $1 )!;
  267.         IF NOT Val($3) = 263 {
  268.             EAlert( "Modula-2 Error:", SubStr($S,8,255) );
  269.         };
  270.         Window(#7);
  271.       };
  272.     }
  273.     ELSE  {
  274.         Beep;
  275.         Select(L.,C.|L:,C:)!;
  276.     }
  277. };
  278.  
  279.  
  280.  
  281. * 03
  282. * Clear error marks, close and Launch Modula-2 shell
  283. "Clear, save & launch/1" {
  284.     Call(07);
  285. * Compile/simulate message 'COMP'  ≈  17231 = C + O = 43H = 4FH;  19792 = M + P = 4DH + 50H 
  286.     IF POSTHL("RAMS","DMEv",17231, 19792, 0) ELSE IF POSTHL("ETHM","DMEv",17231, 19792, 0);
  287. *    IF POSTHL("RAMS","MnCh",129,5,0) ELSE IF POSTHL("ETHM","MnCh",129,5,0);
  288.     Launch( GetStr(2) );
  289. };
  290.  
  291. * --------------------------------------------------------------------------------
  292. * 04
  293. * insert a line in the menu
  294. "-" {};
  295.  
  296. * 05
  297. * Launch Modula-2 shell and Simulate
  298. "Launch shell & simulate/2" •{
  299. * Compile/simulate message 'COMP'  ≈  17231 = C + O = 43H = 4FH;  19792 = M + P = 4DH + 50H 
  300.     IF POSTHL("RAMS","DMEv",17231, 19792, 0) ELSE IF POSTHL("ETHM","DMEv",17231, 19792, 0);
  301.     Launch( GetStr(2) );
  302. };
  303.  
  304.  
  305. * 06
  306. * Launch Modula-2 shell
  307. "Launch shell/3" •{
  308.     Launch( GetStr(2) );
  309. };
  310.  
  311.  
  312. * 07
  313. * Close Modula-2-source file
  314. "Clear error marks & save/8" {
  315.     Select(0,0);
  316.     WHILE EFind ($5)   Clear;
  317.     Save;
  318.     Select(0,0);
  319.     Close;
  320. };
  321.  
  322. * 08
  323. * Remove Modula-2-error marks
  324. * alternate (invisible) errmark: EFIND("")
  325. "Clear error marks/9" {
  326.     Sect(0);
  327.     Select(0,0);
  328.     WHILE EFind ($5)   Clear;
  329. };
  330.  
  331.  
  332.  
  333. * 09
  334. "Configure" •{
  335.     Set( $4, GetStr(0) );
  336.     IF NOT Len($4) = 0  Set($7,$4);
  337.     IF Prompt( "Your last name:", $7 )  {
  338.         IF NOT Len($4) = 0  Set( $6, GetStr(1) );
  339.         IF Prompt( "Your first name:", $6 )  {
  340.             IF NOT Len($4) = 0  Set( $9, GetStr(3) );
  341.             IF Prompt( "Relative path to 'ErrList.DOK':", $9 )  {
  342.                 IF NOT Len($4) = 0  Set( $8, GetStr(2) );
  343.                 IF Prompt( "Name of the Modula-2 shell (e.g. MacMETH):", $8 )  {
  344.                     PutStr( 0, $7 );
  345.                     PutStr( 1, $6 );
  346.                     PutStr( 2, $8 );
  347.                     PutStr( 3, $9 );
  348.                 }
  349.             }
  350.         }
  351.     }
  352. };
  353.  
  354.  
  355. * --------------------------------------------------------------------------------
  356. * 10
  357. * insert a line in the menu
  358. "-" {};
  359.  
  360. * 11
  361. * Insert a DEFINITION MODULE template (Option^M)
  362. "MODULE DEF          Opt M" 346 •{
  363.   IF Prompt("Enter DEF Module name ",$0) {
  364.     New;
  365.     Push;
  366.     Insert("DEFINITION MODULE ");
  367.     Insert($0);
  368.     Insert(";\N");
  369.     Insert("\N");
  370.     Insert("  (*******************************************************************\N");
  371.     Insert("\N");
  372.     Insert("    Module  ");  Insert($0);  Insert("     (Version 1.0)\N");
  373.     Insert("\N");
  374.     Insert(Concat("              Copyright (c) 19",SubStr(Date(2),7,2)," by ",$6," ",$7," and Swiss\N"));
  375.     Insert("              Federal Institute of Technology Zürich ETHZ\N");
  376.     Insert("\N");
  377.     Insert("      Purpose (*.  purpose  .*)\N");
  378.     Insert("              \N");
  379.     Insert("      Remarks (*.  remarks.  .*)\N");
  380.     Insert("              \N");
  381.     Insert("      Programming\N");
  382.     Insert("\N");
  383. *af*    Insert("          o Design and Implementation\N");
  384. *jt*    Insert("          o Design\N");
  385. *or*    Insert("          o Design and Implementation\N");
  386. *tn*    Insert("          o Design\N");
  387.     Insert("          o Design\N");
  388.     Set($3,Concat("              ",SubStr($6,0,1),". ",$7,"         ",Date(2),"\N\N"));
  389.     Insert($3);
  390. *jt*    Insert("          o Implementation\N");  Insert($3);
  391. *tn*    Insert("          o Implementation\N");  Insert($3);
  392.     Insert("          o Implementation\N");  Insert($3);
  393.     Insert("              \N");
  394.     Insert("          Swiss Federal Institute of Technology Zurich ETHZ\N");
  395. *af*     Insert("          Systems Ecology - Institute of Terrestrial Ecology\N");
  396. *jt*     Insert("          Systems Ecology\N");
  397. *or*     Insert("          Systems Ecology\N");
  398. *tn*     Insert("          Systems Ecology\N");
  399. *af*     Insert("          \N");
  400.     Insert("          Systems Ecology - Institute of Terrestrial Ecology\N");
  401. *af*     Insert("          Department of Environmental Sciences\N");
  402. *jt*     Insert("          Department of Environmental Sciences\N");
  403. *or*     Insert("          Department of Environmental Sciences\N");
  404. *tn*     Insert("          Department of Environmental Sciences\N");
  405. *af*     Insert("          Grabenstr. 3\N");
  406. *jt*     Insert("          Grabenstr. 3\N");
  407. *or*     Insert("          Grabenstr. 3\N");
  408. *tn*     Insert("          Grabenstr. 3\N");
  409.     Insert("          Grabenstr. 3\N");
  410.     Insert("          CH-8952 Schlieren/Zurich\N");
  411.     Insert("          Switzerland\N");
  412.     Insert("\N");
  413.     Insert("          Last revision of definition:  ");
  414.     Insert(Concat(Date(2),"  ",SubStr($6,0,1),SubStr($7,0,1),"\N"));
  415.     Insert("\N");
  416.     Insert("  *******************************************************************)\N");
  417.     Insert("\N");
  418.     Insert("\N");
  419.     Insert("  (*.  .*)\N");
  420.     Insert("\N");
  421.     Insert("END ");
  422.     Insert($0);
  423.     Insert(".\N");
  424.     Call(38);
  425.     QSavAs(Concat($0,".DEF"));
  426.   };
  427. };
  428.  
  429.  
  430. * 12
  431. * Insert an IMPLEMENTATION MODULE template
  432. * [for DEF: Opt-M]
  433. "MODULE MOD/M" •{
  434.     IF Prompt("Enter Module name ",$0)  {
  435.       New;
  436.       Push;
  437.       Insert("(*. IMPLEMENTATION  .*)MODULE ");  Insert($0);  Insert(";\N\N");
  438.       Call(36);
  439.       Insert("\N");
  440.       Insert("\N");
  441.       Insert("BEGIN\N");
  442.       Insert("  (*.Statement.*)\N");
  443.       Insert("END ");
  444.       Insert($0);
  445.       Insert(".\N");
  446.       Call(38);
  447.       QSavAs(Concat($0,".MOD"));
  448.     };
  449. };
  450.  
  451.  
  452. * 13
  453. * Derive an empty implementation module from a correct definition module
  454. * NOTE: this version does NOT function CORRECTLY FOR:
  455. *       - syntactically incorrect DEF modules, e.g: unbalanced brackets, etc!
  456. *         ==> compile DEF module before running that macro
  457. *       - DEF modules containing more than 1 section (default = 32K)
  458. *         ==> remove some lengthy comments
  459. *       - if some keywords (i.e: PROCEDURE, END) appear in comments or types.
  460. *         ==> correct manually (anyway: the compiler will notice these errors).
  461. "Module DEF->MOD"  {
  462. * first copy all to a new window:
  463.     Select( 0,0 );
  464.     IF NOT Find( "DEFINITION" )  {
  465.       Alert( "Not as a definition module recognized!" ); }
  466.     ELSE  {
  467.       Select( 0,0 | L$,C$ );
  468.       Copy;
  469.       New;
  470.       Paste;
  471. * substitute DEFINITION by IMPLEMENTATION:
  472.       Select( 0,0 );
  473.       Push;
  474.       Find( "DEFINITION" );
  475.       Clear;
  476.       Insert( "IMPLEMENTATION" );
  477.       Find( " MODULE " );
  478.       Select( L.,C: );
  479.       EFind( "[A-Za-z][A-Za-z0-9]*" );
  480.       Set( $0, $S );
  481. * replace header comment (these string are written by macro "MODULE DEF"):
  482.       Select( L.+1,0 );
  483.       IF Find("(**************************************************")  {
  484.         Select( L.,0 );
  485.         Push;
  486.         Select( L.,C$-3 );
  487.         IF NOT Find("***************************************************)")
  488.           Find("*)");
  489.         Select(L[,C[ | L:,C:)!;
  490.         Drop;
  491.         Clear;
  492.       };
  493.       Call(36);
  494. * leave imports as they are:
  495.       WHILE Find ("IMPORT " )  {
  496.         Find( ";" );
  497.         IF C. = C$    Select( L.+1,0 )
  498.         ELSE          Select( L.  ,C.+1 );
  499.       };
  500. * clear heading const, type, var declarations:
  501. * note: const, type or var later inbetween procs are not filtered!
  502.       Push;
  503.       IF Find( "PROCEDURE " ) {
  504.         Select(L[,C[|L.-1,C$);
  505.         Clear;
  506.         Insert( "\N\N" );  };
  507.       Drop;
  508. * do procedures:
  509.       Select( L.,C.| L$,C$ );
  510.       Call(15);
  511. * make body:
  512.       Select( L$-10,0 );
  513.       WHILE Find( "END " )  {};
  514.       Select( L.,0 );
  515.       IF Find("END ")  {
  516.         Select( L.,0 );
  517.         Insert( "\N" );
  518.         Insert( "BEGIN\N ");
  519.         Insert( "  (*.Statement.*)\N" );  }
  520.       ELSE
  521.         Alert( "Bad syntax, no 'END' of module encountered!" );
  522.     };
  523.     Call(38);
  524.     QSavAs( Concat($0,".MOD") );
  525. };
  526.  
  527.  
  528.  
  529.  
  530. * 14
  531. * insert a PROCEDURE template (Option^P)
  532. "PROCEDURE           Opt P" 335 {
  533.   Push;
  534.   IF Prompt("Enter Procedure name",$2) {
  535.     Insert("PROCEDURE "); Insert($2);
  536. *af*    Insert(";(*. VAR .*)\n");
  537. *jt*    Insert(";(*. VAR .*)\n");
  538. *or*    Insert("( (*. VAR .*) );(*. .*)\n");
  539. *tn*    Insert(";(*. .*)\n");
  540.     Insert("( (*. VAR .*) );(*. .*)\n");
  541. *    Insert("  CONST  (*.Constants.*);\n");
  542. *    Insert("TYPE  (*.Types.*);\n");
  543. *    Insert("  VAR  (*.Variables.*);\n");
  544. *    Insert("\b\bBEGIN\n  (*.Statement.*)\n\b\bEND ");
  545.     Insert("BEGIN\n  (*.Statement.*)\n\b\bEND ");
  546.     Insert($2);
  547.     Insert(";(*. continue... .*)");    
  548.     Call(38);
  549.   };
  550. };
  551.  
  552.  
  553. * 15
  554. * expand the header of a "DEF" procedure to an empty implementation
  555. * assumes that the headers of procs to be expanded are selected before call
  556. * (supports recursive comments in argument list)
  557. * NOTE: that procedure will NOT function CORRECTLY if the brackets of
  558. *   comments or argument list are not balanced!
  559. "Proc[s] DEF->MOD"  {
  560.     Set( #1, L$ );
  561.     Select( L.,C. );
  562.     Push;
  563.     WHILE Find( "PROCEDURE " )  AND  L. < #1  {
  564.       Select( L.,C: );
  565.       EFind( "[A-Za-z][A-Za-z0-9]*" );
  566.       Set( $3, $S );
  567.       Set( #0, -1 );
  568.       IF EFind( "[;(]" )  {
  569.         IF Ord($S) = Ord(";")
  570.           Set( #0, 0 )
  571.         ELSE  {
  572.           Set( #0, 1 );
  573.           WHILE #0 > 0  {
  574.             IF EFind( "[()]" )  {
  575.               IF Ord($S) = Ord("(")  Set( #0, #0+1 )
  576.               ELSE  Set( #0, #0-1 );  }
  577.             ELSE
  578.               Set( #0, -1 );
  579.           };
  580.           IF #0 < 0  OR  NOT Find( ";" )  Set( #0, -1 );
  581.         };
  582.         IF #0 = 0  {
  583.           Select( L.+1, 0 );
  584.           Push;
  585.           Find( "(*" );
  586.           IF L. = L[  {
  587.             IF Find( "*)" )  {
  588.               Select( L[,C[ | L.,C: );
  589.               Clear;
  590.               Drop; }
  591.             ELSE
  592.               Pop;
  593.           }
  594.           ELSE
  595.             Pop;
  596.           Insert( "    (*. VAR .*)\N" );
  597.           Insert( "  BEGIN\N" );
  598.           Insert( "    (*.Statement.*)\N" );
  599.           Insert( "  END " );  Insert( $3 );  Insert( ";\N\N" );
  600. *         we have to add the number of inserted lines to update orig. selection
  601.           Set (#1, #1+5);  }
  602.         }
  603.       ELSE
  604.         Alert( "Bad syntax, no ';' found!" );
  605.     };
  606.     Call(38);
  607. };
  608.  
  609.  
  610.  
  611. * 16
  612. * insert a FOR-TO-DO template (Option^F)
  613. "FOR                       Opt F" 303 {
  614.     Push;
  615.     Insert("FOR (*.loop var.*):= (*.expr.*) TO (*.expr.*) DO\n");
  616.     Insert("  (*.Statement.*)\n");
  617.     Insert("\b\bEND(*FOR*);(*. continue... .*)");    
  618.     Call(38);
  619. };
  620.  
  621.  
  622. * 17
  623. * insert a CASE template (Option^S)
  624. "CASE                     Opt S" 301 {
  625.     Push;
  626.     Insert("CASE (*.expr.*) OF\n");
  627.     Insert("  (*.Constant.*)   : (*.Statement.*)\n");
  628.     Insert("\b\b| (*.Constant.*)   : (*.Statement.*)\n");
  629. *    Insert("\b\bELSE\N  (*.Statement.*);\n");
  630.     Insert("END(*CASE*);(*. continue... .*)");    
  631.     Call(38);
  632. };
  633.  
  634.  
  635. * 18
  636. * insert an IF-THEN-ELSE template (Option^I)
  637. * af version: Option^J is similar to Option^I
  638. * Using I may cause problems since I is diacritical with US-ASCII 
  639. * keyboard, i.e. the first character z typed will eventually carry 
  640. * a "^" if z may be used for a diacritical construction; otherwise
  641. * z will be preceeded by a "^".  In any case the user must first
  642. * delete these characters before he may (re)start with actual typing.
  643. * Remark: Option^J has nothing to do with macro Command J (Jump to line
  644. *         with a particular #)
  645. *af*"IF THEN                 Opt J" 338
  646. *jt*"IF THEN                 Opt J" 338
  647. *or*"IF THEN                 Opt I" 334
  648. *tn*"IF THEN                 Opt I" 334
  649. "IF THEN                 Opt J" 338
  650. {    Push;
  651.     Insert("IF (*.Condition.*) THEN\n  (*.Statement.*)\n");
  652.     Insert("\b\bELSE\n  (*.Statement.*)\n");
  653.     Insert("\b\bEND(*IF*);(*. continue... .*)");    
  654.     Call(38);
  655. };
  656.  
  657.  
  658. * 19
  659. *  Insert a WHILE-DO-END template (Option^W)
  660. "WHILE                   Opt W" 313 {
  661.     Push;
  662.     Insert("WHILE (*.Condition.*) DO\n");
  663.     Insert("  (*.Statement.*)\n");
  664.     Insert("\b\bEND(*WHILE*);(*. continue... .*)");    
  665.     Call(38);
  666. };
  667.  
  668.  
  669. * 20
  670. *  Insert a REPEAT-UNTIL template (Option^R)
  671. "REPEAT                  Opt R" 315 {
  672.     Push;
  673.     Insert("REPEAT\n");
  674.     Insert("  (*.Statement.*)\n");
  675.     Insert("\b\bUNTIL (*. Condition .*);(*. continue... .*)");    
  676.     Call(38);
  677. };
  678.  
  679.  
  680. * 21
  681. *  Insert a WITH-DO-END template (Option^H)
  682. "WITH                     Opt H" 304 {
  683.     Push;
  684.     Insert("WITH (*.Designator.*) DO\n");
  685.     Insert("  (*.Statement.*)\n");
  686.     Insert("\b\bEND(*WITH*);(*. continue... .*)");    
  687.     Call(38);
  688. };
  689.  
  690.  
  691. * --------------------------------------------------------------------------------
  692. * 22
  693. * insert a line in the menu
  694. "-" {};
  695.  
  696.  
  697.  
  698. * 23
  699. * puts comment-braces (like placeholders) around the current selection
  700. "Comment/K" {
  701.     Push;
  702.     Select(L],C]);
  703.     Insert(" .*)");
  704.     Select(L[,C[);
  705.     Insert("(*. ");
  706.     Pop;
  707.     IF L. = L:  Select(L.,C. | L:,C:+8)
  708.     ELSE        Select(L.,C. | L:,C:+5);
  709. };
  710.  
  711.  
  712. * 24
  713. * removes comment-braces at start and end of the current selection 
  714. * af version: (Option^K)
  715. *af*"Uncomment          Opt K" 340
  716. *jt*"Uncomment          Opt K" 340
  717. *or*"Uncomment/U" 340
  718. *tn*"Uncomment/U" 340
  719. "Uncomment          Opt K" 340 
  720. {
  721.     Push;
  722.     Select(L],C]-4 | L],C]);
  723.     Clear;
  724.     Select(L[,C[ | L[,C[+4);
  725.     Clear;
  726.     Pop;
  727. };
  728.  
  729.  
  730.  
  731.  
  732. * 25
  733. * Move all lines in the current selection to the right by inserting
  734. * a double space. do nothing for empty lines.
  735. "Move sel. right/R" {
  736.     Push;
  737.     WHILE L. < L] {
  738.         Select(L.,0);
  739.         IF NOT C$ = 0  Insert("  ");
  740.         Select(L.+1,0)!;
  741.     };
  742.     Select(L[,0|L],0);
  743.     Drop;
  744. };
  745.  
  746.  
  747. * 26
  748. * Move all lines in the current selection one position to the left
  749. * by deleting the leftmost characters. do nothing for empty lines.
  750. "Move sel. left/L" {
  751.     Push;
  752.     WHILE L. < L] {
  753.         Select(L.,0|L.,1);
  754.         Clear;
  755.         Select(L.+1,0)!;
  756.     };
  757.     Select(L[,0|L],0);
  758.     Drop;
  759. };
  760.  
  761.  
  762.  
  763. * 27
  764. * Replace all 'real' tabs by blank strings
  765. * this is useful to convert 'Edit'- to 'MEdit'-files
  766. "Replace tabs" {
  767.     SECT(0);
  768.     Select(0,0);
  769.     WHILE FIND("\9")   Insert("\t");
  770.     BEEP;
  771. };
  772.  
  773.  
  774. * 28
  775. * rearrange comments by wrapping the end of 
  776. * too long lines to the next line or filling lines too short lines
  777. * The comment must already contain comment braces such as "(*" and "*)"
  778. * and the Auto indent on resp. Line wrap around mode off!!!!!
  779. "Wrap comments/A" {
  780. * save current selection and assign last line of selection to #1
  781.     Push; Set(#1,L]);
  782. * set cursor to begin of selection and search for comment begin
  783.     Select(L[,C[); FIND("(*");
  784. * add at end of comment begin a new line in any case, update #1
  785.     Select(L.,C:); Insert("\n  "); Set(#1,#1+1);
  786. * save current selection, which is left margin of comment text
  787.     Push;
  788. * select and clear any blanks or empty lines till begin of text
  789.     WHILE C> = -1 { Select(L.+1,C>) ; Set(#1,#1-1) };
  790.     Select(L.,C>);
  791.     Select(L[,C[ | L:,C<); Clear; Drop;
  792. * WHILE comment:
  793.     WHILE L. < #1
  794.     {
  795. * IF line is too long insert after last whole word an EOL (wrap
  796. * around mode), update #1
  797.         IF C$ > 68
  798.         {
  799.           Select(L.,68); Select(L.,C<);
  800.           Insert("\n"); Set(#1,#1+1);
  801.         }
  802. * ELSE current line is too short, hence remove EOL, update #1, and 
  803. * remove all blanks except for one till begin of next word (fill mode)
  804. * unless it is the last line
  805.         ELSE
  806.         {
  807.           IF L. < #1-1
  808.           {
  809.             Select(L.,C$ | L.+1,0); Clear; Set(#1,#1-1);
  810.             Select(L.,C<); Select(L.,C>); Insert(" ");
  811.             Push;
  812.             Select(L.,C>); Select(L[,C[ | L.,C<); Clear; Drop;
  813.           } ELSE Set(#1,#1-1);
  814.         };
  815.     };
  816. * Find "*)" which is on the current line (was filled in) and
  817. * insert an EOL before it, shift it to the left by 2 columns
  818.     Select(L.,0); FIND("*)"); Select(L.,C.);
  819.     Insert("\n");
  820.     Select(L.,C.-2 | L.,C.);  Clear;
  821. * Add an EOL after comment (has been removed during fill in) and
  822. * restore selection
  823.     Select(L.,C$); Insert("\N");
  824.     Select(L[,C[ | L.,0)!;
  825.     Drop;
  826. };
  827.  
  828.  
  829. * 29
  830. * rearrange text by wrapping the end of 
  831. * too long lines to the next line or filling lines too short lines
  832. * Option ^ W (works if text not commented (s.a. Macro 22)
  833. * left margin of text is given by first word begin in selection
  834. "Wrap text             Opt A" 300 {
  835. * save current selection and assign last line of selection to #1
  836.     Push; Set(#1,L]);
  837. * set cursor to begin of selection
  838.     Select(L[,C[);
  839. * WHILE text:
  840.     WHILE L. < #1
  841.     {
  842. * IF line is too long insert after last whole word an EOL (wrap
  843. * around mode), update #1
  844.         IF C$ > 68
  845.         {
  846.           Select(L.,68); Select(L.,C<);
  847.           Insert("\n"); Set(#1,#1+1);
  848.         }
  849. * ELSE current line is too short, hence remove EOL, update #1, and 
  850. * remove all blanks except for one till begin of next word (fill mode)
  851. * unless it is the last line
  852.         ELSE
  853.         {
  854.           IF L. < #1-1
  855.           {
  856.             Select(L.,C$ | L.+1,0); Clear; Set(#1,#1-1);
  857.             Select(L.,C<); Select(L.,C>); Insert(" ");
  858.             Push;
  859.             Select(L.,C>); Select(L[,C[ | L.,C<); Clear; Drop;
  860.           } ELSE Set(#1,#1-1);
  861.         };
  862.     };
  863. * Add an EOL after text (has been removed during fill in) and
  864. * restore selection
  865.     Select(L.,C$); Insert("\N");
  866.     Select(L[,C[ | L.,0)!;
  867.     Drop;
  868. };
  869.  
  870.  
  871. * --------------------------------------------------------------------------------
  872. * 30
  873. * insert a line in the menu (line separator)
  874. "-" {};
  875.  
  876. *-*************-*
  877. *-* Movements *-*
  878. *-*************-*
  879.  
  880.  
  881. * 31
  882. * Bring last window to front
  883. "Flip windows/H"  {
  884.     Set(#0,0);  WHILE Window(#0)  Set(#0,#0+1);  Window(#0-1);
  885. };
  886.  
  887.  
  888. * 32
  889. * Ask for a line number to jump to and do it
  890. "Jump to Line/J" {
  891.     Prompt("Goto Line",#6);
  892.     Select(#6-1,C. | #6-1,C.)!;
  893. };
  894.  
  895.  
  896. * 33
  897. * jumps to the next placeholder in a Modula-2 structure
  898. * Alternative keyboard entry: Option^G ~ 305
  899. *af*"Placeholder          Opt G/G" 305
  900. *jt*"Placeholder          Opt G/G" 305
  901. *or*"Placeholder          Opt -" 344
  902. *tn*"Placeholder          Opt -" 344
  903. "Placeholder          Opt G/G" 305 
  904. {
  905.     Find("(*.");
  906.     IF L: = 0 AND C: = 0   Find("(*.");
  907.     Push;
  908.     Find(".*)");
  909.     Select(L[,C[ | L:,C:)!;
  910.     Drop;
  911. };
  912.  
  913.  
  914. * 34
  915. * For use together with the following macros
  916. "Save position/B" {
  917.     Push;
  918. };
  919.  
  920.  
  921. * 35
  922. * Jumps back to the last position saved with macro 2 (Option^B)
  923. * the stack can hold the last eight positions
  924. "Back to position   Opt B" 311 {
  925.     Select(L[,C[)!;
  926.     Pop;
  927. };
  928.  
  929.  
  930.  
  931. *==================================================================*
  932. * !!! From here on depending on the version macros with or without *
  933. * menu entries. NOTE: macros with menu entries will function only  *
  934. * properly if they are defined in a sequence from the beginning    *
  935. * without ANY! macro stuck in between WITHOUT menu entry !!!       *
  936. *==================================================================*
  937.  
  938. * ………
  939.  
  940.  
  941. *============================================================*
  942. * !!! Add from here on only(!) macros with NO menu entry !!! *
  943. *============================================================*
  944.  
  945.  
  946. * 36
  947. * insert implementation header info:
  948.     {
  949.       Insert("  (*\N");
  950.       Insert("        Implementation and Revisions:\N");
  951.       Insert("        ============================\N");
  952.       Insert("\N");
  953.       Insert("        Author  Date        Description\N");
  954.       Insert("        ------  ----        -----------\N");
  955.       Insert("\N");
  956.       Insert(Concat("        ",SubStr($6,0,1),SubStr($7,0,1),"      ",Date(2)));
  957.       Insert("    First implementation\N");
  958.       Insert("\N");
  959.       Insert("  *)\N");
  960.       Insert("\N");
  961.       Insert("\N");
  962.       Insert("  (*.imports.*)\N");
  963. };
  964.  
  965. * 37
  966. * delete to end of line   option - BS ~ 351
  967. 351 {
  968.     Select(L.,C.|L.,C$);
  969.     Clear;
  970. };
  971.  
  972.  
  973. * 38
  974. * select first placeholder
  975. * !!!! this macro is called by many other macros !!!!
  976. {
  977.     Pop;
  978.     Find("(*.");
  979.     Push;
  980.     Find(".*)");
  981.     Select(L[,C[ | L:,C:)!;
  982.     Drop;
  983. };
  984.  
  985.  
  986. * 39
  987. * select current word (like double click)
  988. *: <Enter>
  989. (1,76)
  990. {
  991.     Select(L.,C< | L.,C>)!;
  992. }.
  993.  
  994. * --------------------------------------------------------------------------------
  995. *** only a maximum of 60 macros are supported by the MComp = V1.40 ***
  996.